<template>
	<el-row>
		<el-col :span="8"></el-col>
		<el-col :span="8">
			<el-card shadow="never" header="密码重置">
				<el-form ref="form" :model="form" :rules="rules" label-width="100px" status-icon>
					<el-form-item label="新密码" prop="password">
						<el-input v-model="form.password" prefix-icon="el-icon-lock" clearable show-password placeholder="新密码"></el-input>
					</el-form-item>
					<el-form-item label="确认密码" prop="password2">
						<el-input v-model="form.password2" prefix-icon="el-icon-lock" clearable show-password placeholder="确认密码"></el-input>
					</el-form-item>
					<div style="text-align: center;width: 100%">
						<el-button type="primary" :loading="isSetFlag" round @click="submit">重置</el-button>
					</div>
				</el-form>
			</el-card>
		</el-col>
		<el-col :span="8"></el-col>
	</el-row>
</template>

<script>
export default {
	name: 'Reset Password Email',
	data() {
		return {
			isSetFlag: false,
			form: {
				password:'',
				password2:'',
				t:this.$route.query.t
			},
			rules: {
				password: [
					{required: true, message: '请输入登录密码'},
					{validator: (rule, value, callback) => {
							if (this.form.password2 !== '') {
								this.$refs.dialogForm.validateField('password2');
							}
							callback();
						}}
				],
				password2: [
					{required: true, message: '请再次输入密码'},
					{validator: (rule, value, callback) => {
							if (value !== this.form.password) {
								callback(new Error('两次输入密码不一致!'));
							}else{
								callback();
							}
						}}
				]
			},
		}
	},
	mounted() {
	},
	methods: {
		async submit()
		{
			var res = await this.$API.system.user.setPassWordByEmail.post(this.form)
			if(res.code == 200){
				this.$message.success("操作成功")
				location.href="/";
			}else{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
	}
}
</script>

<style>

</style>
